package com.sykj.cloud.system.service.impl;

import com.sykj.cloud.common.core.constant.UserConstants;
import com.sykj.cloud.common.core.utils.DateUtils;
import com.sykj.cloud.common.core.utils.IdUtils;
import com.sykj.cloud.system.api.domain.Member;
import com.sykj.cloud.system.mapper.MemberMapper;
import com.sykj.cloud.system.service.IMemberService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 会员Service业务层处理
 *
 * @author mr.will
 * @date 2021-03-16
 */
@Service
public class MemberServiceImpl implements IMemberService
{
    @Autowired
    private MemberMapper memberMapper;

    /**
     * 新增会员
     *
     * @param member 会员
     * @return 结果
     */
    @Override
    public int insertMember(Member member)
    {
        member.setGuid(IdUtils.fastSimpleUUID());
        member.setCreateTime(DateUtils.getNowDate());
        return memberMapper.insertMember(member);
    }

    @Override
    public Member selectMemberrByLoginName(String loginName) {
        return memberMapper.selectMemberrByLoginName(loginName);
    }

    /**
     * 修改会员
     *
     * @param member 会员
     * @return 结果
     */
    @Override
    public int updateMember(Member member)
    {
        member.setUpdateTime(DateUtils.getNowDate());
        return memberMapper.updateMember(member);
    }

    /**
     * 批量删除会员
     *
     * @param guids 需要删除的会员ID
     * @return 结果
     */
    @Override
    public int deleteMemberByIds(String[] guids)
    {
        return memberMapper.deleteMemberByIds(guids);
    }

    /**
     * 删除会员信息
     *
     * @param guid 会员ID
     * @return 结果
     */
    @Override
    public int deleteMemberById(String guid)
    {
        return memberMapper.deleteMemberById(guid);
    }

    /**
     * 查询会员
     *
     * @param guid 会员ID
     * @return 会员
     */
    @Override
    public Member getMemberById(String guid)
    {
        return memberMapper.getMemberById(guid);
    }

    /**
     * 查询会员列表
     *
     * @param member 会员
     * @return 会员
     */
    @Override
    public List<Member> listMembers(Member member)
    {
        return memberMapper.listMembers(member);
    }

    /**
     * 校验该应用会员登录名是否唯一
     *
     * @param member 会员
     * @return 结果
     */
    @Override
    public String checkMemberLoginName(Member member) {
        int count = memberMapper.checkMemberLoginName(member);
        if (count > 0)
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
